#include "CDailyTaskConfig.h"

int CDailyTaskConfig::Init()
{
    //_astDailyTaskConfigs.m_iUsedCount = MAX_DAILY_TASK_CONFIG;
    _astDailyTaskClassAwardConfigs.m_iUsedCount = MAX_DAILY_TASK_CLASS_CONFIG;
    //_astDailyTaskTboxConfigs.m_iUsedCount = MAX_TBOX_NUM;
    _astSecretaryPayConfigs.m_iUsedCount = MAX_SECRETARY_STYLE_NUM+1;
    _astSecretaryLevelConfigs.m_iUsedCount = MAX_SECRETARY_LEVEL+1;

    for (int i = 0; i < _astDailyTaskConfigs.Size(); ++i)
    {
        _astDailyTaskConfigs[i].Clear();
    }

    for (int i = 0; i < _astDailyTaskClassAwardConfigs.Size(); ++i)
    {
        _astDailyTaskClassAwardConfigs[i].Clear();
    }

    for (int i = 0; i < _astDailyTaskTboxConfigs.Size(); ++i)
    {
        _astDailyTaskTboxConfigs[i].Clear();
    }

    return 0;
}

int CDailyTaskConfig::AddTaskConfig(CDailyTaskConfigData& stConfigData)
{
    if (!stConfigData.HasConfig())
    {
        return ERROR_DTASK_ADD_EMPTY_CONFIG;
    }

    /*if( stConfigData._iTaskId>=_astDailyTaskConfigs.GetCount() )
    {
        return ERROR_DTASK_TASK_ID;
    }

    if (_astDailyTaskConfigs[stConfigData._iTaskId].HasConfig())
    {
        return ERROR_DTASK_DUPLICATED_CONFIG;
    }*/

    //_astDailyTaskConfigs[stConfigData._iTaskId] = stConfigData;
    _astDailyTaskConfigs.AddOneItem( stConfigData );

    return 0;
}

int CDailyTaskConfig::AddTboxAwardConfig( CDailyTaskTboxAwardConfigData & stData)
{
    if (!stData.HasConfig())
    {
        return ERROR_TBOX_ADD_EMPTY_CONFIG;
    }

    if( stData._iTboxId>=_astDailyTaskTboxConfigs.GetCount() )
    {
        return ERROR_TBOX_ID;
    }

    /*if (_astDailyTaskTboxConfigs[stData._iTboxId].HasConfig())
    {
        return ERROR_TBOX_DUPLICATED_CONFIG;
    }

    _astDailyTaskTboxConfigs[stData._iTboxId] = stData;
*/
    _astDailyTaskTboxConfigs.AddOneItem( stData );

    return 0;
}

int CDailyTaskConfig::AddClassAwardConfig( CDailyTaskClassAwardConfigData & stData )
{
    if (!stData.HasConfig())
    {
        return ERROR_CLASS_AWARD_ADD_EMPTY_CONFIG;
    }

    if( stData._iTaskBelongType>=_astDailyTaskClassAwardConfigs.GetCount() )
    {
        return ERROR_CLASS_AWARD_ID;
    }

    if (_astDailyTaskClassAwardConfigs[stData._iTaskBelongType].HasConfig())
    {
        return ERROR_CLASS_AWARD_DUPLICATED_CONFIG;
    }

    _astDailyTaskClassAwardConfigs[stData._iTaskBelongType] = stData;

    return 0;
}

int CDailyTaskConfig::GetTboxAwardConfig(unsigned int iTboxId, CDailyTaskTboxAwardConfigData& stData)
{
    if( iTboxId>= (unsigned int)_astDailyTaskTboxConfigs.GetCount() )
    {
        return ERROR_TBOX_ID;
    }

    /*if( !_astDailyTaskTboxConfigs[iTboxId]._bHasConfig )
    {
        return ERROR_TBOX_ID;
    }*/
    for( int i=0; i<_astDailyTaskTboxConfigs.Size(); ++i )
    {
        if( (unsigned int)_astDailyTaskTboxConfigs[i]._iTboxId == iTboxId )
        {
            stData = _astDailyTaskTboxConfigs[i];
            return 0;
        }
    }

    //stData = _astDailyTaskTboxConfigs[iTboxId];

    return ERROR_TBOX_ID;
}

int CDailyTaskConfig::GetClassAwardConfig(unsigned int iTaskBelongType, CDailyTaskClassAwardConfigData& stData)
{
    if( iTaskBelongType>= (unsigned int)_astDailyTaskClassAwardConfigs.GetCount() )
    {
        return ERROR_CLASS_AWARD_ID;
    }

    if( !_astDailyTaskClassAwardConfigs[iTaskBelongType]._bHasConfig )
    {
        return ERROR_CLASS_AWARD_ID;
    }

    stData = _astDailyTaskClassAwardConfigs[iTaskBelongType];

    return 0;
}

int CDailyTaskConfig::GetTaskConfig(unsigned int iTaskID, CDailyTaskConfigData& stData)
{
    /*if( iTaskID >= (unsigned int)_astDailyTaskConfigs.GetCount() )
    {
        return ERROR_DTASK_TASK_ID;
    }*/

/*
    if( !_astDailyTaskConfigs[iTaskID]._bHasConfig )
    {
        return ERROR_DTASK_TASK_ID;
    }
    */
    for( int i=0; i<_astDailyTaskConfigs.Size(); ++i )
    {
        if( (unsigned int)_astDailyTaskConfigs[i]._iTaskId == iTaskID )
        {
            stData = _astDailyTaskConfigs[i];
            return 0;
        }
    }

    //不能根据id取
    //stData = _astDailyTaskConfigs[iTaskID];

    return ERROR_DTASK_TASK_ID;
}

int CDailyTaskConfig::AddSecretaryPayConfig( CSecretaryPayConfigData& stData )
{
    if (!stData.HasConfig())
    {
        return ERROR_SECRETARY_PAY_ADD_EMPTY_CONFIG;
    }

    if( stData._iStyleId>=_astSecretaryPayConfigs.GetCount() )
    {
        return ERROR_SECRETARY_STYLE_ID;
    }

    if (_astSecretaryPayConfigs[stData._iStyleId].HasConfig())
    {
        return ERROR_SECRETARY_PAY_ADD_EMPTY_CONFIG;
    }

    _astSecretaryPayConfigs[stData._iStyleId] = stData;

    return 0;
}

int CDailyTaskConfig::GetSecretaryPayConfig(int _iStyleId, CSecretaryPayConfigData& stData)
{
    if( _iStyleId>= _astSecretaryPayConfigs.GetCount() )
    {
        return ERROR_SECRETARY_STYLE_ID;
    }

    if( !_astSecretaryPayConfigs[_iStyleId]._bHasConfig )
    {
        return ERROR_SECRETARY_STYLE_ID;
    }

    stData = _astSecretaryPayConfigs[_iStyleId];

    return 0;
}

int CDailyTaskConfig::AddSecretaryLevelConfig( CSecretaryLevelConfigData& stData )
{
    if (!stData.HasConfig())
    {
        return ERROR_SECRETARY_LEVEL_ADD_EMPTY_CONFIG;
    }

    if( stData._iLevel>=_astSecretaryLevelConfigs.GetCount() )
    {
        return ERROR_SECRETARY_LEVEL_ID;
    }

    if (_astSecretaryLevelConfigs[stData._iLevel].HasConfig())
    {
        return ERROR_SECRETARY_LEVEL_ID;
    }

    _astSecretaryLevelConfigs[stData._iLevel] = stData;

    return 0;
}

int CDailyTaskConfig::GetSecretaryLevelConfig(int iLevel, CSecretaryLevelConfigData& stData)
{
    if( iLevel>= _astSecretaryLevelConfigs.GetCount() )
    {
        return ERROR_SECRETARY_LEVEL_ID;
    }

    if( !_astSecretaryLevelConfigs[iLevel]._bHasConfig )
    {
        return ERROR_SECRETARY_LEVEL_ID;
    }

    stData = _astSecretaryLevelConfigs[iLevel];

    return 0;
}

